//
//  FKProfileNavBar.m
//  NeteaseEdu
//
//  Created by xmc06 on 16/9/28.
//  Copyright © 2016年 zmosa. All rights reserved.
//

#import "FKProfileNavBar.h"
#import <Masonry/Masonry.h>

@implementation FKProfileNavBar

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews
{
    self.backgroundColor = fk_navGrayColor;
    
    UIButton *leftItem = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftItem setImage:[UIImage imageNamed:@"icon-settings_20x44_"] forState:UIControlStateNormal];
    [leftItem setImage:[UIImage imageNamed:@"icon-settings-selected_20x44_"] forState:UIControlStateHighlighted];
    [self addSubview:leftItem];
    self.leftItem = leftItem;
    [leftItem sizeToFit];
    
    UIButton *rightItem = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftItem setImage:[UIImage imageNamed:@"message-icon_20x44_"] forState:UIControlStateNormal];
    [leftItem setImage:[UIImage imageNamed:@"message-icon-selected_20x44_"] forState:UIControlStateHighlighted];
    [self addSubview:rightItem];
    self.rightItem = rightItem;
    [rightItem sizeToFit];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [self addSubview:titleLabel];
    self.titleLabel = titleLabel;
    [titleLabel sizeToFit];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.leftItem mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.centerY.equalTo(self.mas_centerY);
    }];
    
    [self.rightItem mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-10);
        make.centerY.equalTo(self.mas_centerY);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);
    }];
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    
    self.titleLabel.text = title;
}

@end
